﻿
@using ZBJF.Warranty.WebProvider
@{
    ViewBag.Title = "销售商列表";
}
@section Header{
    @Scripts.Render("~/bundles/datatable")
    @Styles.Render("~/Content/datatable")
}
@model ZBJF.Warranty.Model.SellersType
    <ul class="nav nav-tabs">
        <li class="active"><a href="/SellersType/">销售商类型</a></li>
    </ul>
<form id="searchForm">
    <div>

        <label>销售商类型名称</label>
        @Html.TextBox("SellerTypeName1", "", new { maxlength = 20, @class = "input-small" })
        <label style="padding-top: 8px; padding-left: 20px;">
            <input id="btnSubmit" class="btn btn-primary Search-R" type="button" value="查询" onclick="search();">
        </label>
    </div>
</form>
<div class="table-responsive dataTables_wrapper">
    <label class="Add-R">
        <a id="AddNewRole" class="btn btn-xs btn-primary" data-toggle="modal" href="" onclick="showAddNewAdmin('',0,false)" title="添加新销售类型">
            <i class="icon-plus-sign bigger-130"></i>
            添加新销售类型
        </a>
    </label>
    <br />
    @Html.Hidden("ID")
    <table id="sellersTypeList" class="table table-striped table-bordered table-hover">
        <thead>
            <tr>
                <th width="20">序号</th>
                <th width="100">销售商类型</th>
                <th width="80">是否启用</th>
                <th width="80">创建时间</th>
                <th width="100">操作</th>
            </tr>
        </thead>
    </table>
</div>
<div id="shows">
    <table style="margin:0 auto;line-height:50px;">
        <tr>
            <th>销售商类型：</th>
            <td>@Html.TextBoxFor(m => m.SellerTypeName, new { maxlength = 15, @class = "input-small", @style = "width:130px;" })</td>
        </tr>
        <tr>
            <th>是否启用：</th>
            <td>@Html.CheckBoxFor(m => m.IsAvailable)<span>启用</span></td>
        </tr>
    </table>
</div>
@section scripts{
    @Scripts.Render("~/Bundles/ImagePreview")
    <script type="text/javascript">
        var indexs;
        window.onload = function () {
            $("#shows").hide();
        }
        var isSearch = false;
        $(function () {
            var objTable = $("#sellersTypeList")
                .dataTable({
                    fnDrawCallback: function () {
                        ControlPermissionOperate();
                    },
                    "sAjaxSource": "/SellersType/Index",
                    aoColumns: [
                        {
                            "mData": null,
                            "bSortable": false,
                            "fnRender": function (nRow) {
                                return nRow.iDataRow + 1;
                            }
                        },
                        { "mData": "SellerTypeName" },
                        { "mData": "ID" },
                        { "mData": "CreateTime" },
                        { "mData": "ID" }
                    ],
                    "fnRowCallback": function (nRow, aData, iDisplayIndex) {
                        $('td:eq(2)', nRow).html(aData.IsAvailable ? bootStrapOkIncon : bootStrapRemoveIncon);
                        var html = "<a class='Edit-R' target='_blank' href=\"javascript:showAddNewAdmin('" + aData.SellerTypeName + "'," + aData.ID + "," + aData.IsAvailable + ")\" title='编辑'><i class='icon-edit'></i></a>";
                        html += "<a class='Edit-R' href=\"javascript:UpdateStatus('" + aData.ID + "'," + !aData.IsAvailable + ",'/SellersType/UpdateSellersTypeStatus','sellersTypeList')\" title='" + (aData.IsAvailable ? "禁用" : "启用") + "'>" + (aData.IsAvailable ? bootStrapRemoveIncon : bootStrapOkIncon) + "</a>";
                        $('td:eq(4)', nRow).html(html);
                    }
                });
            imgPreview();
        });

        function imgPreview() {
            setTimeout(function () { $("img.preview").preview(); }, 500);
        }

        function showAddNewAdmin(sellerTypeName, sellerTypeId, isAvailable) {
            var title = sellerTypeId > 0 ? "修改销售商类型" : "添加销售商类型";
            $("#ID").val(sellerTypeId);
            indexs = layer.open({
                type: 1,
                title: title, //标题栏
                closeBtn: false,
                area: '600px;',
                shade: 0.8,
                id: 'LAY_layuipro' //设定一个id，防止重复弹出
                ,
                resize: false,
                btn: ['确认', '取消'],
                btnAlign: 'c', //按钮排列
                yes: function (index, layero) {
                    UpdateSellersType();
                },
                moveType: 1, //拖拽模式，0或者1
                content: $('#shows').show()
            });
            $("#SellerTypeName").val(sellerTypeName);
            $("#IsAvailable").attr("checked", isAvailable);
        }

        function UpdateSellersType() {
            var id = $("#ID").val() * 1;
            var sellerTypeName = $("#SellerTypeName").val().trim();
            var isAvailable = $("#IsAvailable").is(':checked');
            if (sellerTypeName == null) {
                layer.alert("请输入销售商类型名称");
            }
            $.ajax({
                url: "/SellersType/UpdateSellersType?ID=" + id,
                type: "post",
                data: {
                    "SellerTypeName": sellerTypeName,
                    "IsAvailable": isAvailable
                },
                dataType: "json",
                success: function (data) {
                    if (data.success) {
                        layer.alert(data.message);
                        location.href = '/SellersType/';
                    } else {
                        layer.alert(data.message);
                    }
                }
            });
        }
        function search() {
            /*给查询对象赋值*/
            queryParamList.SellerTypeName = $("#SellerTypeName1").val().trim();
            $("#sellersTypeList").dataTable().fnDraw();
            imgPreview();
        }
    </script>
}